package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.atguigu.spzx.model.entity.sys.SysRole;
import com.atguigu.spzx.model.entity.sys.SysUser;
import com.atguigu.spzx.model.vo.common.R;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/admin/product/brand")
@Tag(name="商品品牌管理")
public class BrandController {
    @Resource
    BrandService brandService;

    @Operation(summary = "新增品牌")
    @PostMapping("save")
    public R save(@RequestBody Brand brand){
        brandService.save(brand);
        //有些需求需要返回新增成功的角色对象给前端回显(需要绑定id)
        return R.ok();
    }
    @Operation(summary = "删除指定品牌")
    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable("id") Long id){
        brandService.deleteByIds(Arrays.asList(id));
        return R.ok();
    }
    @Operation(summary = "查询指定品牌")
    @GetMapping("getById/{id}")
    public R getById(@PathVariable("id") Long id){
        Brand brand = brandService.getById(id);
        return R.ok("item",brand);
    }
    @Operation(summary = "更新指定品牌")
    @PutMapping("update")
    public R update(@RequestBody Brand brand){
        brandService.update(brand);
        //有些需求需要返回新增成功的角色对象给前端回显(需要绑定id)
        return R.ok();
    }
    @Operation(summary = "查询品牌分页数据")
    @GetMapping("list/{pageNum}/{pageSize}")
    public R list(@PathVariable("pageNum") Integer pageNum ,
                  @PathVariable("pageSize") Integer pageSize){
        PageInfo<Brand> pageInfo =  brandService.list(pageNum,pageSize);
        return R.ok("page" , pageInfo);
    }

    @Operation(summary = "查询所有品牌")
    @GetMapping("list")
    public R list(){
        List<Brand> list =  brandService.list();
        return R.ok("items" , list);
    }
}
